import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useSysInfo = defineStore(
  'sysInfo',
  () => {
    const sysInfo = ref({})
    // 新增：存储底部安全栏高度（响应式变量）
    const safeAreaBottom = ref(0)

    const setSysInfo = (info) => {
      console.log(info, 'sysinfo')
      sysInfo.value = info
      const safeHeight = info.safeArea?.height || 0;
      const windowHeight = info.windowHeight || 0;
      safeAreaBottom.value = windowHeight - safeHeight ||0
    }

    return {
      sysInfo,
      safeAreaBottom, // 导出新增的变量
      setSysInfo,
    }
  },
  {
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
